#coding=utf-8
__author__ = 'Meteor'

from flask import Flask
from flask import request

import json
app = Flask(__name__)


@app.route('/sys/login',methods=['GET','POST'])
def login():
    if request.method == 'GET':
        return '请求方式不支持'

    form = request.form
    if not form:
        return '请求参数不能为空'
    if form.get('username') and form.get('password') and form.get('role'):

        response = {'code': 2, 'message': '登录成功', 'data': {'user': {'account': form.get('username'), 'passWord':form.get('password'), 'name': form.get('username'), 'createDate': '2019-12-30 11: 23: 08', 'status': 0, 'models': [
                {'modelCode': 1, 'modelName': '采购管理'
                },
                {'modelCode': 2, 'modelName': '销售管理'
                },
                {'modelCode': 3, 'modelName': '系统管理'
                },
                {'modelCode': 4, 'modelName': '财务管理'
                },
                {'modelCode': 5, 'modelName': '仓库管理'
                },
                {'modelCode': 6, 'modelName': '业务报表'
                }
            ]
        }, 'token': '20210909141215'
    }
}

    return json.dumps(response,ensure_ascii=False)



@app.route('/main/system/user/show')
def show_user():
    if request.method != 'GET':
        return '请求方式必须是get'
    if request.args.get('page'):
        response = {
	"total":3,
	"list":[
		{ "account":"lisi","passWord":"12345","id":"李四", "createDate":"2018-10-01","status":0,"models":None},
		{"account":"wangwu","passWord":"555","id":"王五","createDate":"2016-11-09","status":0,"models":None},
		{"account":"wangwu1","passWord":"1212","id":"121","createDate":"2019-05-09 12:54:41","status":0,"models":None}
	],
	"pageNum":request.args.get('page'),
	"pageSize":10,
	"size":3,
	"startRow":1,
	"endRow":3,
	"pages":1,
	"prePage":0,
	"nextPage":0,
	"isFirstPage":True,
	"isLastPage":True,
	"hasPreviousPage":False,
	"hasNextPage":False,
	"navigatePages":8,
	"navigatepageNums":[1],
	"navigateFirstPage":1,
	"navigateLastPage":1
}
    return json.dumps(response,ensure_ascii=False)


@app.route('/main/system/user/add',methods = ['POST'])
def add_user():
    form = request.form
    if form.get('account') and form.get('name') and form.get('passWord') and form.get('createDate') and form.get('status') and form.get('modelcodes'):
        response = {"code":2, "message": "添加用户成功", "data": None}
    return json.dumps(response,ensure_ascii=False)

app.run()
# if __name__ == '__main__':
#     app.run()

